#include <bits/stdc++.h>
#include <climits>
using namespace std;

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int left = 0; int right = 0;
        int n = nums.size();
        int sum = 0;
        int ans = INT_MAX;
        while(right <= n){
            if(sum < target && right==n) break;
            if(sum < target) sum+=nums[right++];
            else {
                ans = min(ans, right-left);
                sum -= nums[left++];
            }
        }
        if(ans == INT_MAX) return 0;
        else return ans;
    }
};